import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';
import set from '@dfeidao/atom-mobile/local/set';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import render from '@dfeidao/atom-mobile/render/render';

export default async function a002(fd: IFeidaoAiMobile, e: Event, page_no: number) {
	// onEndReached
	// console.log('onEndReached', page_no);
	if (!page_no) {
		return;
	}
	const teacher_no = get(fd, 'teacher_no');
	const productid = get(fd, 'productid');
	const res = get(fd, 'res') as [];
	const d = await nodejs<Array<{}>>('app-leave-record/s001', {
		teacher_no,
		productid,
		page_no
	});
	// console.log(d, '---------d----------');
	if (d.length === 0) {
		page_no = page_no - 1;
	}
	const data = [...res, ...d];
	await set(fd, 'res', data);
	render(fd, { dt: data, page_no, new_len: d.length });
}
